home *** CD-ROM | disk | FTP | other *** search
/ 9-Digit Zip Code Directory / 9-Digit Zip Code Directory (American Business Information) (ABIZIP-12).ISO / z4src.zip / BSMSCDEX.C < prev    next >
C/C++ Source or Header  |  1993-04-21  |  4KB  |  171 lines

  1. //----------------------------------------------------------------------------
  2. //                            MODULE DESCRIPTION
  3. //
  4. //  Module:    bsmscdex.c
  5. //   Title:    Base library
  6. //  Notice:    John M. Weeder
  7. //                 Copyright (c) 1993. All rights reserved.
  8. //             This module contains proprietary information and should be 
  9. //                treated as confidential.
  10. //
  11. //----------------------------------------------------------------------------
  12. //                           MAINTENANCE HISTORY
  13. //
  14. // $Workfile$
  15. // $Revision$
  16. //   $Author$
  17. //     $Date$
  18. //      $Log$    
  19. //
  20. //----------------------------------------------------------------------------
  21. //                             MODULE NARRATIVE
  22. //
  23. //
  24. //    This module contains MSCDEX support. This support is only valid under DOS.
  25. //
  26. //    The code in this module should be written entirely in C. 
  27. //    Do not use any C++ constructs.
  28. //
  29. //    This module is portable to:
  30. //        DOS 3.X+
  31. //        MS Windows 3.X+
  32. //        OS/2 2.X+
  33. //        OS/2 2.0 PM
  34. //        SCO UNIX.
  35. //
  36. //    The following compilers are supported:
  37. //        MSC 6.0A
  38. //        MSC/C++ 7.0
  39. //        Borland C++ 3.1 for DOS
  40. //        Borland C++ 1.0 for OS/2 2.X
  41. //        SCO UNIX cc
  42. //
  43. //----------------------------------------------------------------------------
  44. #include <bs.h>
  45.  
  46.  
  47. //----------------------------------------------------------------------------
  48. //   Description:    Return drive id of first CDROM drive
  49. //    Parameters:    psDrive        Variable to return drive id in.
  50. //                                        Drive = 'A', 'B',...
  51. //       Returns:    TRUE if MSCDEX installed.
  52. //----------------------------------------------------------------------------
  53. BOOL FN_E MscdexFirstDrive(PSHORT psDrive)
  54. {
  55. #if OS_DOS || OS_WINDOWS
  56.     USHORT usDriveCnt;
  57.     SHORT sDrive;
  58.  
  59.     _asm {
  60.         mov    ax, 01500h
  61.         xor    bx, bx
  62.         int    2Fh
  63.         mov    [usDriveCnt], bx
  64.         mov    [sDrive], cx
  65.         }
  66.  
  67.     if (psDrive && usDriveCnt)
  68.         psDrive[0] = sDrive + 'A';
  69.  
  70.     return usDriveCnt != 0;
  71. #else
  72.     NOTUSED(psDrive);
  73.     return FALSE;
  74. #endif                                            // #if OS_DOS
  75. }
  76.  
  77.  
  78. //----------------------------------------------------------------------------
  79. //   Description:    Check if a drive is a CDROM
  80. //    Parameters:    sDrive        Drive to check.
  81. //                                        1=A, 2=B or 'A', 'B', ...
  82. //       Returns:    TRUE if valid CDROM drive.
  83. //----------------------------------------------------------------------------
  84. BOOL FN_E MscdexIsCdrom(SHORT sDrive)
  85. {
  86. #if OS_DOS || OS_WINDOWS
  87.     USHORT usSignature;
  88.     USHORT usResult;
  89.  
  90.  
  91.     if (sDrive >= 'A' && sDrive <= 'Z')
  92.         sDrive = (SHORT)(sDrive - 'A');
  93.  
  94.     if (sDrive >= 'a' && sDrive <= 'z')
  95.         sDrive = (SHORT)(sDrive - 'a');
  96.  
  97.     if (sDrive < 0 || sDrive >= 26)
  98.         return FALSE;
  99.  
  100.     _asm {
  101.         mov    ax, 0150Bh
  102.         xor    bx, bx
  103.         mov    cx, [sDrive]
  104.         int    2Fh
  105.         mov    [usSignature], bx
  106.         mov    [usResult], ax
  107.         }
  108.  
  109.     return usResult && usSignature == 0xADAD;
  110. #else
  111.     NOTUSED(sDrive);
  112.     return FALSE;
  113. #endif                                            // #if OS_DOS
  114. }
  115.  
  116.  
  117. //----------------------------------------------------------------------------
  118. //   Description:    Check if MSCDEX is installed
  119. //    Parameters:
  120. //       Returns:    TRUE if MSCDEX installed.
  121. //----------------------------------------------------------------------------
  122. BOOL FN_E MscdexIsInstalled(void)
  123. {
  124. #if OS_DOS || OS_WINDOWS
  125.     USHORT usDriveCnt;
  126.     _asm {
  127.         mov    ax, 01500h
  128.         xor    bx, bx
  129.         int    2Fh
  130.         mov    [usDriveCnt], bx
  131.         }
  132.     return usDriveCnt != 0;
  133. #else
  134.     return FALSE;
  135. #endif                                            // #if OS_DOS
  136. }
  137.  
  138.  
  139. //----------------------------------------------------------------------------
  140. //   Description:    Run standard test suite
  141. //    Parameters:    sTest        Test to run.
  142. //                                        0        Run all default tests (except).
  143. //       Returns:    TRUE if successful.
  144. //----------------------------------------------------------------------------
  145. #if COMPILE_TEST
  146. BOOL FN MscdexTest(SHORT sTest)
  147. {
  148.     NOTUSED(sTest);
  149.     if (MscdexIsInstalled())
  150.         {
  151.         SHORT sDrive;
  152.  
  153.         Output("MSCDEX is installed.\n");
  154.         if (!MscdexFirstDrive(&sDrive))
  155.             return FALSE;
  156.  
  157.         Output("First CDROM drive is %c:.\n", sDrive);
  158.         for (sDrive = 'A'; sDrive <= 'Z'; ++sDrive)
  159.             if (MscdexIsCdrom(sDrive))
  160.                 Output("Drive %c: is a CDROM.\n", sDrive);
  161.         }
  162.     else
  163.         Output("MSCDEX is not installed.\n");
  164.  
  165.     return TRUE;
  166. }
  167. #endif
  168. //----------------------------------------------------------------------------
  169. //------------------------------- End of File --------------------------------
  170. //----------------------------------------------------------------------------
  171.